<template>
  <div id="app">
    <!-- router-view会匹配route中注册的组件 -->
    <router-view v-if="isRouterAlive"/>
  </div>
</template>

<script>

export default {
  name: "App",
  created () {
	    // 在页面加载时读取localStorage
	    if (localStorage.getItem('store')) {
	      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem('store'))))
	    }
	    // 在页面刷新时将store保存到localStorage里
	    window.addEventListener('beforeunload', () => {
	      localStorage.setItem('store', JSON.stringify(this.$store.state))
	    })
	  },
    // 以下内容用来完成局部刷新
    provide() {
      return{
        reload: this.reload
      }
    },
    data() {
      return {
        isRouterAlive:true
      }
    },
    methods: {
      reload() {
        this.isRouterAlive = false;
        this.$nextTick(() => {
          this.isRouterAlive = true;
        })
      }
    }
};

</script>

<style>
#app {
  /* font-family: "Avenir", Helvetica, Arial, sans-serif; */
  /* -webkit-font-smoothing: antialiased; */
  /* -moz-osx-font-smoothing: grayscale; */
  /* text-align: center; */
  /* color: #2c3e50;  */
  /* margin-top: 60px; */
  box-sizing: border-box;
}
</style>
